import 'package:flutter/material.dart';
import '../res/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  // 生命周期函数:当组件初始化的时候就会触发
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 9, vsync: this);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // 左侧按钮图标
        leading: IconButton(
          onPressed: () {
            print("左侧按钮图标");
          },
          // color: Colors.white,
          icon: Icon(Icons.menu),
        ),
        backgroundColor: Colors.red, // 导航背景颜色
        foregroundColor: Colors.white, // 导航文字颜色
        title: Text("Flutter Demo"),
        // 右侧按钮图标
        actions: [
          IconButton(
            icon: Icon(Icons.search),
            onPressed: () {
              print("搜索");
            },
          ),
          IconButton(
            icon: Icon(Icons.more_horiz),
            onPressed: () {
              print("更多");
            },
          ),
        ],
        bottom: TabBar(
          isScrollable: true,
          indicatorColor: Colors.white,
          indicatorWeight: 2,
          indicatorSize: TabBarIndicatorSize.label,
          // indicator: BoxDecoration(
          //   // color: Colors.blue,
          //   // borderRadius: BorderRadius.circular(10)
          // ),
          labelColor: Colors.white,
          labelStyle: TextStyle(
            fontWeight: FontWeight.bold
          ),
          unselectedLabelColor: Colors.grey,
          unselectedLabelStyle: TextStyle(
            fontWeight: FontWeight.normal
          ),
          // indicatorPadding: EdgeInsets.all(5),
          controller: _tabController,
          tabs: [
            Tab(child: Text("关注")),
            Tab(child: Text("热门")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
            Tab(child: Text("视频")),
          ],
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          ListView(children: [ListTile(title: Text("我是关注列表"))]),
          ListView(children: [ListTile(title: Text("我是热门列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
          ListView(children: [ListTile(title: Text("我是视频列表"))]),
        ],
      ),
    );
  }
}
